﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>授课内容</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="../../static/css/font.css" rel="stylesheet" />
    <link href="../../static/css/weadmin.css" rel="stylesheet" />
    <link href="../../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../../../lib/layui/layui.js"></script>

</head>
<body>
    <div class="layui-fluid" id="infos">
        <table id="dataList" lay-filter="dataList"></table>
    </div>
    <div class="layui-fluid fluid-position">
        <div class="layui-form">
            <div class="layui-card">
                <div class="layui-card-header">
                    <div class="layui-row layui-col-space10 layui-btn-container">
                        <button type="button" class="layui-btn layui-btn-primary" id="find" name="查询"><i class="layui-icon">&#xe615;</i>查询</button>
                        <button type="button" class="layui-btn layui-btn-primary" id="reset" name="清空"><i class="layui-icon">&#xe669;</i>清空</button>
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-collapse" lay-accordion lay-filter="infos_form">
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">培训资料</h2>
                            <div class="layui-colla-content">
                                <div class="layui-form layui-form-pane">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">文件名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" placeholder="文件名称" maxlength="50" class="layui-input" id="TFName" name="TFName" />
                                        </div>
                                    </div>
                                    <!--计划名称-->
                                    <!--<div class="layui-form-item">
                                        <label class="layui-form-label">计划名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" placeholder="计划名称" class="layui-input" maxlength="50" id="TPName" name="TPName" />
                                        </div>
                                    </div>-->
                                    <!--时间-->
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">上传时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="TFAddDateTime" />
                                            </div>
                                            <label class="layui-form-label layui-form-label-inner layui-form-label-inner-w1">至</label>
                                            <div class="layui-input-inline layui-form-label-inner">
                                                <input type="text" class="layui-input" id="TFAddDateTime2" name="TFAddDateTime2" />
                                            </div>
                                        </div>

                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-form-label">选择部门</div>
                                        <div class="layui-input-block">
                                            <select id="selectDept" name="selectDept" lay-filter="selectDept">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                    </div>
                                   
                                </div>

                            </div>
                        </div>
                    </div>

                </div>
                <div class="layui-card-header layui-btn-container">

                </div>
            </div>
        </div>
    </div>

    <script>
        var contollerName = "TrainFiles";//api url的一部分  ，控制器名
        var selectCurrentTPID = 0;//计划id
        var selectCurrentID = 0;// 当前选中的 id  [用于修改]
        var selectCurrentName = "";//选择当前信息的name

        var currentDeptLevelId = 0;//当前部门级别  0：是段
        var currentInfoDeptId = 0;//当前选中信息的 部门id
        var currentPreDepId = 0;//当前上级部门id
        var selectdata = function () {
            var data = {
                objList: selectobjs
            }
            return data;
        };

        var selectIDs = [];//选中的id列表 [可用批量删除  审核 取消 ]
        var selectobjs = [];//
        var deptList = [];//部门列表



        //加载 [赋值]获取数据  (部门相关数据)
        var dataSelect = [];
        var temp_deptId_List = [];//列表中选择信息时   使用字段中的内容=>为其赋值,可以使用此字段保存
      
        var dataCurent = [];
        var th = 0;
        var tw = 0;

        layui.use(['form', 'laydate', 'table', 'jquery', 'element', 'layer', 'tree', 'util'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            th = $(document).height();
            tw = $(document).width();
            var table = layui.table;
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            var eleTree = layui.tree;
            laydate.render({ elem: '#TFAddDateTime', trigger: 'click' });
            laydate.render({ elem: '#TFAddDateTime2', trigger: 'click' });
            function formRenderSelect() {
                form.render('select');
            }
            form.on('switch(switch)', function (data) { });
            laydate.render({ elem: '#TPReleaseStart', trigger: 'click' });
            laydate.render({ elem: '#TPReleaseEnd', trigger: 'click' });
            function PageInit() {
                var obj = $("div[lay-id='dataList']");
                var child = $(".layui-table-body");
                var off = obj.offset().top;
                var c = th - off - 100;
                child.attr("style", "height:" + c + "px");
            }
            element.on('collapse(infos_form)', function (data) {
                PageInit();
            });
            var selfType = GetQueryString("plan");
            $.ajax({
                url: ApiUrl + "Dep/SelTree",
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        dataSelect = data.Data;
                        //$("#DepID").append("<option value=''></option>");
                        //$(data.Data).each(function (index, item) {
                        //    $("#DepID").append("<option value='" + item.DepID + "'>" + item.DepName + "</option>");
                        //});
                        //form.render();//必须，不然动态加载项不显示
                    }
                    else if (data.StatusCode == 403) {
                        //layer.alert(data.Info, function () {
                        //    location.href = './login.html';
                        //})
                    }
                    else {
                        //layer.msg(data.Info);
                    }
                }
            });
            var tempList = [];
            function SetTextFromTree(v) {
                for (var i = 0; i < v.length; i++) {
                    var c = v[i];
                    tempList.push({ id: c.id, title: c.title });
                    temp_deptId_List.push(c.id);
                    var a = $("#selectDatas").val();
                    if (a != "") { a += ","; }
                    $("#selectDatas").val(a + c.title);
                    if (c.children != undefined) {
                        if (c.children.length > 0) {
                            SetTextFromTree(c.children);
                        }
                    }
                }
            }
            function setTree()//选择信息列表中 信息时 调用该方法  并为temp_deptId_List赋值
            {
                eleTree.setChecked('eleTreeid', temp_deptId_List);
            }
            var el_tree;
            $("#selectDatas").on("click", function (e) {
                e.stopPropagation();
                loadTree();
                $(".eleTree").toggle();
            });
            function loadTree() {
                el_tree =
                    eleTree.render({
                        elem: '.eleTree',
                        id: 'eleTreeid',
                        data: dataSelect,
                        defaultExpandAll: false,
                        expandOnClickNode: false,
                        highlightCurrent: true
                        , checkStrictly: true
                        , showCheckbox: true
                        , oncheck: function (obj) {
                            $("#selectDatas").val("");
                            temp_deptId_List = [];
                            tempList = [];
                            SetTextFromTree(el_tree.getChecked());
                        }
                    });
            }

            function showList() {
                var swhere = JSON.stringify({
                    start: $("#TPReleaseStart").val(),
                    end: $("#TPReleaseEnd").val(),
                    TFUploadDeptID: $("#selectDept").val().trim(),
                    TFName: $("#TFName").val()
                });
                table.render({
                    elem: '#dataList'
                    , url: ApiUrl + contollerName + '/Search'
                    , id: "dataList"
                    , headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    }
                    , page: true
                    , cols: [[
                        { type: 'checkbox' },
                        { field: 'TFID', title: '编号', sort: true, hide: true },
                        { field: 'TFParentID', title: '父编号', sort: true, hide: true },
                        { field: 'TFName', title: '资料名称', width: 550 },
                        { field: 'FTID', title: 'FTID', hide: true },
                        { field: 'KKID', title: 'KKID', hide: true },
                        { field: 'TFPath', title: '资料路径', hide: true },
                        { field: 'TFSize', title: '资料大小', hide: true },
                        { field: 'TFMD5', title: '资料密码', hide: true },
                        { field: 'TFUseCount', title: '使用数量', hide: true},
                        { field: 'TFIsPass', title: '是否加密', hide: true },
                        { field: 'TFAddUserID', title: '添加人员id', hide: true },
                        { field: 'TFAddUserName', title: '添加人员姓名', width: 120 },
                        {
                            field: 'TFAddDateTime', title: '添加时间', width: 120, templet: function (d) {
                                return d.TFAddDateTime.substring(0, 10);
                            },
                        },
                        { field: 'TFUploadDeptID', title: '上传部门id', hide: true },
                        { field: 'TFServerPath', title: 'TFServerPath', hide: true },
                        { field: 'TFFileKey', title: 'TFFileKey', hide: true },
                        { field: 'TFFileLevel', title: 'TFFileLevel', hide: true },
                        { field: 'TFReadTime', title: 'TFReadTime', hide: true },
                        { field: 'TFDownCount', title: '下载数量', hide: true},
                        { field: 'DepID', title: '部门id', hide: true},
                        {
                            field: 'TFEndDateTime', title: '截至时间', width: 120, templet: function (d) {
                                if (d.TFEndDateTime != null) {
                                    return d.TFEndDateTime.substring(0, 10);
                                }
                                else {
                                    return "";
                                }
                            },
                        }

                    ]]
                    , where: { swhere: swhere }
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": res.StatusCode, //解析接口状态
                            "msg": res.Info, //解析提示文本
                            "count": res.Count, //解析数据长度
                            "data": res.Data //解析数据列表
                        };
                    },
                    response: { statusCode: 200 },//规定成功的状态码，默认：0
                    event: true,
                    page: true,
                    done: function (res, curr, count) {
                        //如果是异步请求数据方式，res即为你接口返回的信息。
                        //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                        if (res.code == 403) {
                            layer.alert(res.msg, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                    }
                });
            }
            $(function () {
                showList();
                $("#sreach").click(function () {
                    showList();
                })
            })
            PageInit();
            function clearForm() {
                $("textarea").val("");
                $("input").val("");
            }
            //获取当前 部门级别id,部门id,上级部门id
            //$.ajax({
            //    url: ApiUrl + "Dep/DeptLevel",//SelTree
            //    type: 'post',
            //    headers: {
            //        "userid": JSON.parse(window.localStorage.authInfo).UserId,
            //        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
            //    },
            //    success: function (data) {
            //        if (data.StatusCode == 200) {
            //            currentDeptLevelId = data.Data.currentDeptLevelId;
            //            cuurentDeptId = data.Data.cuurentDeptId;
            //            currentPreDepId = data.Data.currentPreDepId;
            //        }
            //        else if (data.StatusCode == 403) {
            //            layer.alert(data.Info, function () {
            //                location.href = './login.html';
            //            })
            //        }
            //        else {
            //            layer.msg(data.Info);
            //        }
            //    }
            //});

            //读取部门列表
            $.ajax({
                url: ApiUrl + "Dep/Sel",//SelTree
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        for (var i = 0; i < data.Data.length; i++) {
                            var item = data.Data[i];
                            deptList.push({ id: item.DepID, name: item.DepName });
                        }
                        GetSelectList(deptList, $("#selectDept"), formRenderSelect);
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            top.location.href = "http://" + top.location.host + "/login.html";
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });
           
            //展示一条信息
            function GetSingleInfo(data) {
            
                $("#TFName").val(data.TFName);
                SetselectValue($("#selectDept"),data.DepID, formRenderSelect);
                //$("#TContent").val(data.TContent);
                //$("#IsRelease").val(data.IsRelease);
                //temp_deptId_List = [];
                //if (data.TPID != null) {
                //    prePlanId = data.TPID;
                //}
                //currentInfoDeptLevelId = data.TCDepLevel;
                //currentInfoDeptId = data.TCDepID;
                //var r = GetDept(currentInfoDeptId);
                //if (r == 1) {
                //    if (data.TCSendDepID != null) {
                //        if (data.TCSendDepID.indexOf(',') > -1) {
                //            var tpids = data.TCSendDepID.split(',');
                //            for (var i = 0; i < tpids.length; i++) {
                //                temp_deptId_List.push(Number(tpids[i]));
                //            }
                //        }
                //        else {
                //            temp_deptId_List.push(Number(data.TCSendDepID));
                //        }
                //        setTree();
                //    }
                //}
                //add by cjh
                //selectCurrentIsCheckStatus = data.IsCheck;
                //selectCurrentIsReleaseStatus = data.IsRelease;
            }

            ///按钮操作 开始
            //监听行单击事件（单击事件为：rowDouble）
            table.on('row(dataList)', function (obj) {
                var checked = false;
                var objcheck = $(obj.tr.selector).find("td").eq(0).find(".layui-table-cell").eq(0).find("div").eq(0);
                if (selectIDs.indexOf(obj.data.TFID) > -1) {
                    objcheck.removeClass("layui-form-checked");
                }
                else {
                    objcheck.addClass("layui-form-checked"); checked = true;
                }
                if (checked) {
                    if (obj.data.TFID != undefined) {
                        selectCurrentID = obj.data.TFID;
                        selectIDs.push(obj.data.TFID);
                        selectobjs.push(obj.data);
                        GetSingleInfo(obj.data);
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        var dataList = table.checkStatus("dataList").data;
                        for (var i = 0; i < dataList.length; i++) {
                            var item = dataList[i];
                            selectobjs.push(item);
                            selectIDs.push(item.TFID);
                            if (i == dataList.length - 1) {
                                GetSingleInfo(item);
                                selectCurrentID = item.TFID;
                            }
                        }
                    }
                }
                else {
                    if (obj.data.TFID != undefined) {
                        selectIDs.splice(selectIDs.indexOf(obj.data.TFID), 1);
                        for (var i = 0; i < selectobjs.length; i++) {
                            if (selectobjs[i].TFID == obj.data.TFID) {
                                if (i == selectobjs.length - 1) {
                                    selectCurrentID = 0;
                                    selectCurrentName = "";
                                    if (i > 0) {
                                        if (selectobjs[i - 1].TFID != undefined) {
                                            selectCurrentID = selectobjs[i - 1].TFID;
                                            GetSingleInfo(selectobjs[i - 1]);
                                        }
                                    }
                                    else {
                                        clearForm(); selectCurrentID = 0;
                                    }
                                }
                                selectobjs.splice(i, 1);
                                break;
                            }
                        }
                        if (selectIDs <= 0) {
                            temp_deptId_List = [];
                        }
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        clearForm();
                        temp_deptId_List = [];
                    }
                }
            });
            table.on('checkbox(dataList)', function (obj) {
                if (obj.data.AutoID == undefined) {
                    selectIDs = [];
                    selectCurrentID = 0;
                    selectobjs = [];
                    if (obj.checked) {
                        var dataList = table.checkStatus("dataList").data;
                        for (var i = 0; i < dataList.length; i++) {
                            var item = dataList[i];
                            selectobjs.push(item);
                            selectIDs.push(item.TFID);
                            if (i == dataList.length - 1) {
                                GetSingleInfo(item);
                                selectCurrentID = item.TFID;
                            }
                        }
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        clearForm();
                        temp_deptId_List = [];
                        //var r = GetDept(cuurentDeptId);
                        //if (r == 1) {
                        //    setTree();
                        //}
                    }
                }
            });


            $("#find").click(function () {
                showList();
            });


            $("#reset").click(function () {
                clearForm();
                temp_deptId_List = [];
                //GetDept(currentPreDepId);
                //setTree();
            });

            //end
        });
    </script>
</body>
</html>